import java.io.IOException;
import java.net.ServerSocket;
import java.util.ArrayList;

public class NetWork {
    private final ArrayList<Client> clients = new ArrayList<>();
    public void addClients(Client client) {
        clients.add(client);
        sendMessageForChat(client.name + ": Join in Chat", client.name);
    }

    public void sendMessageForChat(String message) {
        for (Client client: clients) {
            client.sendMessage(message);
        }
    }

    public void sendMessageForChat(String message, String name) {
        for (Client client: clients) {
            if (!client.name.equals(name)) {
                client.sendMessage(message);
            }
        }
    }

    public void removeClients(Client client) throws IOException {
        clients.remove(client);
        sendMessageForChat(client.name + " has left chat!!!", client.name);
    }
}
